// https://leetcode.cn/problems/check-if-number-is-a-sum-of-powers-of-three/
// Created by ade on 2022/12/9.
//
#include<iostream>
#include<vector>
#include<unordered_map>
#include<math.h>

using namespace std;

class Solution {
public:
    bool checkPowersOfThree(int n) {
        cout << getLeft(n) << endl;
        return true;
    }

    int getLeft(int n) {
        int left = 0, right = n;
        int mid = 0;
        while (left < right) {
            cout << "l:" << left << ",r:" << right << endl;
            mid = left + (right - left) / 2;
            int res = pow(3, mid);
            if (res == n) return 0;
            if (res > n) right = mid - 1;
            else left = mid + 1;
        }
        return n - pow(3, mid);
    }
};


int main() {
    Solution so;
    so.checkPowersOfThree(10);
    return 0;
}